package algorithms;

import java.util.Set;

/**
 * @author Yuval Kesten
 *         <ul>
 *         A variant of {@link Dic}. The support, which we prune and discover
 *         item sets upon, is calculated according to the number of baskets the
 *         algorithm has seen since it started discovering item sets of the same
 *         size.
 *         </ul>
 */
public class ProbabilisticDic extends Dic {

	private int lowerBound;

	public ProbabilisticDic(String pathFormat, int startIndex, int endIndex, int _m, Set<String> alphabetSet,
			int estimatedNumOfBaskets, int lowerBound) throws Exception {
		super(pathFormat, startIndex, endIndex, _m, alphabetSet, estimatedNumOfBaskets);
		this.lowerBound = lowerBound;
	}

	@Override
	public int getSupportAsInt(double support, long discoveryIndex) {

		long upperBound = estimatedNumOfBaskets;
		long numOfBasketsForCalculation = basketIndex - discoveryIndex + 1;

		// assert (kDiscoveryIndices.containsKey(k));
		numOfBasketsForCalculation = numOfBasketsForCalculation < upperBound ? numOfBasketsForCalculation : upperBound;
		numOfBasketsForCalculation = numOfBasketsForCalculation > lowerBound ? numOfBasketsForCalculation : lowerBound;
		return (int) (support * numOfBasketsForCalculation);
	}
}
